var muted = "unmuted";
var playState = "playing";

function setupTransportButtions(sender) {
    new button(sender.findName("playButton"), sender.findName("playButtonBackground"), "gray", "dimgray", playClick);
    new button(sender.findName("stopButton"), sender.findName("stopButtonBackground"), "gray", "dimgray", stopClick);
    new button(sender.findName("muteButton"), sender.findName("muteButtonBackground"), "gray", "dimgray", muteClick);
    new button(sender.findName("volumeUpButton"), sender.findName("volumeUpButtonBackground"), "gray", "dimgray", volumeUpClick);
    new button(sender.findName("volumeDownButton"), sender.findName("volumeDownButtonBackground"), "gray", "dimgray", volumeDownClick);
}

function muteClick(sender,args) {
    var muteIcon = sender.findName("muteIcon");
    if (muted == "unmuted") {
        mediaElement.IsMuted = 1;
        muted = "muted";
        muteIcon.opacity = .5;
    }
    else {
        mediaElement.IsMuted = 0;
        muted = "unmuted";
        muteIcon.opacity = 0;
    }
}

function stopClick(sender,args) {
    mediaElement.Stop(); 
    playState = "stopped";
    var pauseIcon = sender.findName("pauseIcon");
    pauseIcon.opacity = 0;
    var playIcon = sender.findName("playIcon");
    playIcon.opacity = 1;
}

function volumeUpClick(sender,args) {
    mediaElement.Volume = mediaElement.Volume + .05;
}

function volumeDownClick(sender,args) {
    mediaElement.Volume = mediaElement.Volume - .05;
}

function playClick(sender,args) {
    if (playState == "playing") {
        playState = "paused";
        mediaElement.Pause();
        var pauseIcon = sender.findName("pauseIcon");
        pauseIcon.opacity = 0;
        var playIcon = sender.findName("playIcon");
        playIcon.opacity = 1;
    }
    else {
        playState = "playing";
        mediaElement.Play();
        var pauseIcon = sender.findName("pauseIcon");
        pauseIcon.opacity = 1;
        var playIcon = sender.findName("playIcon");
        playIcon.opacity = 0;
    }
}

function seekMouseUp(sender, args) {
    if (loaded) {
        var scaleTransform = sender.findName("scaleTransform");
        var offset = (args.x - (73 * scaleTransform.scaleX)) / (321 * scaleTransform.scaleX);
    
        offset = mediaElement.naturalDuration.seconds * offset;
        var timeSpan = mediaElement.position;
        timeSpan.seconds = offset;
        mediaElement.position = timeSpan;
    }
}